package com.nami.store.biz.convertask.service;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nami.store.api.request.conversation.task.ConverTaskAddReq;
import com.nami.store.api.response.task.ConverTaskDTO;
import com.nami.store.biz.convertask.convert.ConverTaskConvert;
import com.nami.store.biz.convertask.repository.ConverTaskRepository;
import com.nami.store.domain.ConverTaskDO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class ConverTaskDomainServiceImpl implements ConverTaskDomainService {

    private final ConverTaskRepository converTaskRepository;

    @Override
    public List<ConverTaskDTO> getTask(Integer pageIndex, Integer pageSize) {
        Page<ConverTaskDO> tasks = converTaskRepository.getTask(pageIndex, pageSize);
        return ConverTaskConvert.INSTANCE.convertList(tasks.getRecords());
    }

    @Override
    public boolean batchDel(List<Long> ids) {
        return converTaskRepository.batchDel(ids);
    }

    @Override
    public boolean addConverTask(String taskKey) {
        return converTaskRepository.addConverTask(taskKey);
    }

    @Override
    public boolean batchSave(List<ConverTaskAddReq> tasks) {
        if (CollUtil.isEmpty(tasks)) {
            return false;
        }
        List<ConverTaskDO> list = ConverTaskConvert.INSTANCE.convertList2(tasks);
        return converTaskRepository.batchSave(list);
    }

    @Override
    public boolean insert(List<ConverTaskAddReq> batch) {
        List<ConverTaskDO> taskList = ConverTaskConvert.INSTANCE.convertList2(batch);
        return converTaskRepository.insert(taskList);
    }

}
